//
//  GetFileSize.m
//  xpkc
//
//  Created by wanmeizty on 14-9-2.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "GetFileSize.h"

@implementation GetFileSize
/**
 *  获取文件的大小
 *
 */
//单个文件的大小
+ (long long) fileSizeAtPath:(NSString*) filePath{
    NSFileManager* manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath]){
        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
    }
    return 0;
}
//遍历文件夹获得文件夹大小，返回多少M
+ (float ) folderSizeAtPath:(NSString*) folderPath{
    NSFileManager* manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:folderPath]) return 0;
    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
    NSString* fileName;
    long long folderSize = 0;
    while ((fileName = [childFilesEnumerator nextObject]) != nil){
        if ([fileName hasSuffix:@"pcm"]||[fileName hasSuffix:@"mp4"]) {
            NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
            folderSize += [self fileSizeAtPath:fileAbsolutePath];
        }
    }
    return folderSize/(1024.0*1024.0);
}
@end
